//图片初始化
/*(function initImg(){
	if($('#img').val() != ''){
		var img = document.createElement("img");
		img.src = $('#img').val();
		var parent = document.querySelector('.upImg');
		parent.appendChild(img);
	}
})();*/

//生成二维码
$('.doerweima').on('click',function(){
	var text = $('.erweima').val();
	var imgUrl = $('.upImg').find('img').attr('url');
	console.log(imgUrl);
	$.ajax({
		type:"POST",
		url : "/eshop/backEshop/doErweimaAction.json",
		dataType : "json",
		data : {
			"text" :text,
			'erweimaLogo':imgUrl
		},
		success : function(data) {
			console.log(data);
			if(data['code']=="200"){
				$('.modelBg').show();
				$('.modelContentWrap').show();
				$('html,body').css('overflow','hidden');
				var img = document.createElement("img");
				img.src = $('#img').val()+data['data'];
				var parent = document.querySelector('.imgErweima');
				parent.innerHTML = '';
				parent.appendChild(img);
				$('.downloadA').attr('href',$('#img').val()+data['data']);
			}else {	
				alert("生成二维码失败！");
			}
		}
	})
})

//上传logo
function upImg(input){
	var files = input.files[0];
	var img = document.createElement("img");
	var data = new FormData();
	data.append('erweimaLogo', files);
	$.ajax({
	    url: '/eshop/backEshop/uploadLogo.do',
	    type: 'POST',
	    dataType:'json',
	    cache: false,
	    data: data,
	    processData: false,
	    contentType: false,
	    success:function(res){
	    	if(res['code'] == 200){
	    		img.src = $('#img').val()+res['data'];
	    		img.setAttribute('url',$('#path').val()+res['data']);
		    	var parent = document.querySelector('.upImg');
		    	parent.appendChild(img);
	    	}
	    },error:function(){
	    }
	})
}
//选择常用logo
$('.commonLogoList').on('click','img',function(){
	$('.upImg').find('img').remove();
	var img = document.createElement("img");
	img.src = $(this).attr('src');
	img.setAttribute('url',$(this).attr('url'));
	var parent = document.querySelector('.upImg');
	parent.appendChild(img);
})

//二维码下载到本地
/*$('.downloadImg').on('click',function(){
	var imgHttpUrl = $('.imgErweima').find('img').attr('src');
	$.ajax({
		type:"POST",
		url : "/eshop/backEshop/downloadErweima.json",
		dataType : "json",
		data : {
			"imgHttpUrl" :imgHttpUrl
		},
		success : function(data) {
			if(data['code']=="200"){
				alert('已下载到桌面');
			}else {	
				alert("下载失败！");
			}
		}
	})
})*/
/*$('.downloadImg').on('click',function(){
	try {
        var Message = "\u8bf7\u9009\u62e9\u6587\u4ef6\u5939"; //选择框提示信息
        var Shell = new ActiveXObject("Shell.Application");
        var Folder = Shell.BrowseForFolder(0, Message, 64, 17); //起始目录为：我的电脑
        //var Folder = Shell.BrowseForFolder(0, Message, 0); //起始目录为：桌面
        if (Folder != null) {
            Folder = Folder.items(); // 返回 FolderItems 对象
            Folder = Folder.item(); // 返回 Folderitem 对象
            Folder = Folder.Path; // 返回路径
            if (Folder.charAt(Folder.length - 1) != "\\") {
                Folder = Folder + "\\";
            }
            document.getElementById(path).value = Folder;
            return Folder;
        }
    }
    catch (e) {
        alert(e.message);
    }
})*/

/*function browseFolder(path) {
    try {
        var Message = "\u8bf7\u9009\u62e9\u6587\u4ef6\u5939"; //选择框提示信息
        var Shell = new ActiveXObject("Shell.Application");
        var Folder = Shell.BrowseForFolder(0, Message, 64, 17); //起始目录为：我的电脑
        //var Folder = Shell.BrowseForFolder(0, Message, 0); //起始目录为：桌面
        if (Folder != null) {
            Folder = Folder.items(); // 返回 FolderItems 对象
            Folder = Folder.item(); // 返回 Folderitem 对象
            Folder = Folder.Path; // 返回路径
            if (Folder.charAt(Folder.length - 1) != "\\") {
                Folder = Folder + "\\";
            }
            document.getElementById(path).value = Folder;
            return Folder;
        }
    }
    catch (e) {
        alert(e.message);
    }
}*/